<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script language="javascript" type="text/javascript"
	src="houtai/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
function save(){
	if(confirm("保存信息？")){
	var abc=document.getElementById("baba").innerHTML;
	//alert(abc);
		if(abc=="在线课程"&&ckcouname() && ckcouaddress() && ckcoumoney()&&flag){
		
		
		document.getElementById("form2").submit();
		return true;
		}
	if(abc=="现场课程"&&ckcouname() && ckcouaddress() && ckcoumoney()&&ckcoutime()&&flag){

		document.getElementById("form2").submit();
		return true;
		}
		return false;
	}else{
		return false;
	}
}
var xmlhttp;
	function a1(){
	var tname = document.getElementById("tcname").value;
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = rr;
	
		xmlhttp.open("get", "<%=request.getContextPath()%>/CourseServlet?param=selectTname&tname="
						+ tname + "&time=" + new Date().getTime(), true);
		xmlhttp.send(null);

	}
	var flag = true;
	function rr() {

		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {

				var ss = xmlhttp.responseText;
				document.getElementById("tid").innerHTML = ss;
				if (ss == "存在") {
					//alert("cunzai");
					flag = true;
				} else {
					
		
					flag = false;
				}
			}
		}
return flag;
	}

	function ckcouname() {
		var couname = document.getElementById("couname").value;
		if (couname.trim().length==0) {
			document.getElementById("scouname").style.color = "red";
			document.getElementById("scouname").innerHTML = "课程名不能为空";
			return false;
		}
		document.getElementById("scouname").style.color = "green";
		document.getElementById("scouname").innerHTML = "√";
		return true;
	}
	function ckcouaddress() {
		var couaddress = document.getElementById("couaddress").value;
		if (couaddress.trim().length==0) {
			document.getElementById("scouaddress").style.color = "red";
			document.getElementById("scouaddress").innerHTML = "地址不能为空";
			return false;
		}
		document.getElementById("scouaddress").style.color = "green";
		document.getElementById("scouaddress").innerHTML = "√";
		return true;
	}
	function ckcoumoney() {
		var coumoney = document.getElementById("coumoney").value;
		var mag = /^\d+$/;
		if (coumoney.trim().length==0) {
			document.getElementById("scoumoney").style.color = "red";
			document.getElementById("scoumoney").innerHTML = "价格不能为空";
			return false;
		}
		if (!mag.test(coumoney)) {
			document.getElementById("scoumoney").style.color = "red";
			document.getElementById("scoumoney").innerHTML = "请输入数字,也不要输入空格";
			return false;
		}
		document.getElementById("scoumoney").style.color = "green";
		document.getElementById("scoumoney").innerHTML = "√";
		return true;
	}
	
	function ckcoutime() {
		var otime = document.getElementById("otime").value;
		var etime = document.getElementById("etime").value;
		if(otime<etime){
		document.getElementById("setime").style.color = "green";
		document.getElementById("setime").innerHTML = "√";
		return true;
		}else{
		document.getElementById("setime").style.color = "red";
		document.getElementById("setime").innerHTML = "结课时间不能小于开课时间";
		return false;
		}
		
	}
	

	 function ckall() {
		if(ckcouname() && ckcouaddress() && ckcoumoney() && ckcoutime()){
		       save();
		       return true;
		}else{
			return false;
		}
	} 
	
	function aa() {
		var baba = document.getElementById("baba").innerHTML.trim();
		if (baba=="在线课程") {
			document.getElementById("trotime").style.display="none";
			document.getElementById("tretime").style.display="none";
		}if (baba=="现场课程") {
			document.getElementById("trotime").style.display="";
			document.getElementById("tretime").style.display="";
		}
	}
	
window.onload=aa;
</script>
</head>
<body>
	<table width="100%" height="100%" border="0" cellspacing="0"
		cellpadding="3">
		<tr>
			<td style="height:25px; background-color:#f3f3f3; font-weight:bold"
				valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置： <img
				src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
				<img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
				<img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;课程管理
			</td>
		</tr>
		<tr>
			<td
				style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="20" height="34"><img
							src="houtai/images/main_headerL.gif" width="20" height="34"></td>
						<td style="color:#90c8e8;"><img
							src="houtai/images/icon_card.gif" width="16" height="16"
							align="absmiddle">&nbsp;&nbsp;<strong>修改课程</strong></td>
						<td align="right" class="white" style="padding-right:20px"><a
							href="javascript:history.go(-1);" class="barBtn"><img
								src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a> <a
							href="javascript:history.go(+1);" class="barBtn"><img
								src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a> <a
							href="javascript:history.go(0);" class="barBtn"><img
								src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="100%" valign="top">
				<form id="form2" action="<%=basePath%>/CourseServlet?param=courseUpdate"
					method="post" >
					<div style="overflow:auto;height:100%; width:100%">

						<table width="100%" border="0" cellpadding="3" cellspacing="1"
							class="table1">
							<TR>

								<th width="20%" align="center">课程名<input type="hidden"
									name="couid" value="${CourseById.couId }" /></th>
								<TD class="BGCgray"><input type="text"
									value="${CourseById.couName}" name="couname" id="couname"
									onblur="ckcouname()" /> <span id="scouname"></span></TD>
							</TR>
							<TR>
								<th align="center">上课地点</th>
								<TD width="80%" class="BGCgray"><input type="text"
									value="${CourseById.couAddress}" name="couaddress"
									id="couaddress" onblur="ckcouaddress()" /> <span
									id="scouaddress"></span></TD>
							</TR>
							<TR>
								<th align="center">课程类型</th>
								<TD class="BGCgray"><span id="baba">${CourseById.couType==1?"现场课程":CourseById.couType==0?"在线课程":"未知错误"}</span>
								</TD>
							</TR>
							<TR>
								<th align="center">状态</th>
								<TD class="BGCgray"><c:if test="${CourseById.couType==1}">
										<select name="coustate" id="coustateid">
											<option ${CourseById.couState==1?"selected='selected'":"" }>可报名</option>
											<option ${CourseById.couState==2?"selected='selected'":"" }>报名结束</option>
										</select>
									</c:if> <c:if test="${CourseById.couType==0}">
										<select name="coustate">
											<option ${CourseById.couState==3?"selected='selected'":"" }>可购买</option>
											<option ${CourseById.couState==4?"selected='selected'":"" }>已下架</option>

										</select>
									</c:if></TD>
							</TR>
							<TR>
								<th align="center">讲师</th>
								<TD class="BGCgray"><input type="text" id="tcname"
									name="tname" onblur="a1()" value="${CourseById.user.useName }" />
									<span id="tid"></span></TD>
							</TR>
							<TR>
								<th align="center">价格</th>
								<TD class="BGCgray"><input type="text"
									value="${CourseById.couMoney}" name="coumoney"
									onblur="ckcoumoney()" id="coumoney" /> <span id="scoumoney"></span>
								</TD>
							</TR>
							<TR id="trotime">
								<th align="center">开课时间</th>
								<TD class="BGCgray"><input type="text"
									value="${CourseById.couOpentime}" name="otime"
									readonly="readonly"
									onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate"
									id="otime" /></TD>
							</TR>
							<TR id="tretime">
								<th align="center">预计结课时间</th>
								<TD class="BGCgray"><input type="text"
									value="${CourseById.couEndtime}" name="etime"
									readonly="readonly"
									onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate"
									id="etime" onblur="ckcoutime()"/><span id="setime"></span></TD>
							</TR>
						</table>
					</form>
						<div style="width:100%; text-align:center; padding:5px">
							<BUTTON type="button" style="HEIGHT:25px" onClick="return save()">
								<img src="houtai/images/btn_save.gif" width="16" height="16"
									align="absmiddle"> 保存
							</BUTTON>

							<BUTTON type="button" style="HEIGHT:25px" onClick="javascript:goBack()">
								<img src="houtai/images/btn_back.gif" width="16" height="16" align="absmiddle"> 返回
							</BUTTON>
						</div>
					</div>
				
			</td>
		</tr>
	</table>
</body>
</html>